<template>
  <div class="video-wrapper">
    <div class="play-wrapper" @click="handleClick">
      <transition name="fade">
        <div class="play-button" v-if="!playing">
          <img class="play-icon" :src="bofang" alt="">
        </div>
      </transition>
    </div>
    <video
      id="head-video"
      poster="https://wpimg.wallstcn.com/59276138-3e1d-40c9-b0ec-e93c166a35d1.png  "
      :src="videosrc"
      :controls="playing"
    >
    </video>
  </div>
</template>

<script>
import bofang from '@/assets/bofang.svg'
export default {
  data() {
    return {
      bofang,
      playing: false,
      videosrc: "https://wpimg.wallstcn.com/447a984c-6eb4-4b49-bd1d-26be926f72cf.mp4"
    }
  },
  mounted() {
    this.$video = document.getElementById('head-video')
    this.$video.addEventListener('ended', () => {
      this.playing = false
    })
    if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
      this.videosrc="https://wpimg.wallstcn.com/512ca5f0-1484-44e2-bf68-440f9a37cc16.MP4"
    }
  },
  methods: {
   handleClick() {
     this.playing = !this.playing
     if(this.playing) {
      this.$video.play()
      // console.log(this.$video)
     } else {
       this.$video.pause()
     }
   }
  }
}
</script>

<style scoped>
.video-wrapper {
  background: transparent;
  position: relative;
}
.play-wrapper {
  background: transparent;
  position: absolute;
  left: 15%;
  height: 50%;
  margin: 0 auto;
  width: 70%;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  cursor: pointer;
}
.play-button {
  position: relative;
  z-index: 100;
  top: 30px;
  background:  rgba(128, 128, 128, .7);
  width: 65px;
  height: 65px;
  border-radius: 100px;
}
.play-icon{
  height: 30px;
  position: relative;
  top: 18px;
  left: 26px;
}
video {
  z-index: 10;
}
.fade-enter-active, .fade-leave-active {
  transition: opacity .3s ease;
}
.fade-enter, .fade-leave-to {
  opacity: 0
}
</style>

